<?php
namespace control;
// 生产看板
class productionKanbanClass extends adIndexClass
{
    private const page = 'productionKanban';
    private const title = '生产看板';
    /*返回网页*/
    public function home()
    {
        $month = date("Y-m");
        //and date_format(recordDate, '%Y-%m') = '$month'
        //and date_format(teamNo, '%Y-%m') = '$month'
        $totalPlan = find([
                'table'  => "machining_send_order",
                'field'  => "IFNULL(sum(num),0) as num",
                'single' => " coid = '".self::$coid."' and classify = '生产派工' and state = '已确认' ",
            ])['num']*1 ?? 0;
        $totalPlan += find([
                'table'  => "machining_card as a join machining_card_detail as b on a.id = b.orderId",
                'field'  => "IFNULL(sum(a.num),0) as num",
                'single' => " a.coid = '".self::$coid."' ",
            ])['num']*1 ?? 0;
        $totalYield = find([
                'table'  => "process_report",
                'field'  => "IFNULL(sum(yield),0) as num",
                'single' => " coid = '".self::$coid."' and classify = '工序报工' and state = '已确认' ",
            ])['num']*1 ?? 0;
        $completionRate = $totalPlan>0?round($totalYield/$totalPlan,2)*100:0;

        $totalPlan = "<a class='cursor' onclick=\"newIframe('工序报工','" . root . "control/adIndex.html?cla=processReport&fun=home&state=已确认')\">$totalPlan</a>";
        $totalYield = "<a class='cursor' onclick=\"newIframe('工序报工','" . root . "control/adIndex.html?cla=processReport&fun=home&state=已确认')\">$totalYield</a>";
        $completionRate = "<a class='cursor' onclick=\"newIframe('工序报工','" . root . "control/adIndex.html?cla=processReport&fun=home&state=已确认')\">$completionRate</a>";

        //班组产量
        $process_report = find(array(
            "table"=>"process_report",
            "field"=>"teamId,IFNULL(sum(yield),0) as num",
            "where"=>" coid = '".self::$coid."' and classify = '工序报工' and state = '已确认' group by teamId order by num desc limit 20 "
        ));
        $li = "";
        foreach ((array)$process_report['array'] as $i=>$array){
            $team = query("team"," id = '$array[teamId]' ","name");
            $sendNum = find([
                    'table'  => "machining_send_order",
                    'field'  => "IFNULL(sum(num),0) as num",
                    'single' => " coid = '".self::$coid."' and classify = '生产派工' and state = '已确认' and teamId = '$array[teamId]' ",
                ])['num'] ?? 0;
            $rate = $sendNum>0?round($array['num']/$sendNum*100,1):0;
            $li .= "<li>
                    <p>".($i+1)." {$team['name']}</p>
                    <p><progress value='".$rate."' max='100'></progress></p>
                </li>";
        }
        $style = count((array)$process_report['array'])<13?" style='display: none;' ":"";
        $team_yield = "
            <ul id='comment1'>
                {$li}
            </ul>
            <ul id='comment2' $style></ul>
            ";

        //产线生产进度
        $process_report = find(array(
            "table"=>"process_report",
            "field"=>"lineId,IFNULL(sum(yield),0) as num",
            "where"=>" coid = '".self::$coid."' and classify = '工序报工' and state = '已确认' group by lineId order by num desc limit 5 "
        ));
        $li = "";
        foreach ((array)$process_report['array'] as $i=>$array){
            $product_line = query("product_line"," id = '$array[lineId]' ","name");
            $sendNum = find([
                    'table'  => "machining_send_order",
                    'field'  => "IFNULL(sum(num),0) as num",
                    'single' => " coid = '".self::$coid."' and classify = '生产派工' and state = '已确认' and lineId = '$array[lineId]' ",
                ])['num'] ?? 0;
            $rate = $sendNum>0?round($array['num']/$sendNum*100,1):0;
            $li .= "<li>
                    <span class='progress-name'>{$product_line['name']}</span>
                    <span class='progress-name'>{$rate}%</span>
                </li>";
        }
        $line_progress = "
            <ul id='comment3'>
                {$li}
            </ul>
            ";
        //材料耗用    and date_format(b.recordDate, '%Y-%m') = '$month'
        $arr = find(array(
            "table"=>"machining_order_detail as a join machining_order as b on a.orderId = b.id",
            "field"=>"a.materialId,IFNULL(sum(quantity),0) as quantity",
            "where"=>" a.coid = '".self::$coid."' and b.state = '已确认'  group by a.materialId "
        ));
        $quantity = array_column((array)$arr['array'],'quantity');
        $max = empty($quantity)?0:max($quantity);
        $li = "";
        foreach ((array)$arr['array'] as $i=>$array){
            $material = query("material"," id = '$array[materialId]' ","code,name,unit");
            //领料
            $pickNum=0;
            $pickOrderAll = find(array(
                'table'=>'pick_order as a join pick_order_detail as b on a.id = b.orderId',
                "where"=>"a.state = '已确认' and a.type=0 and b.materialId = '$array[materialId]'"
            ));
            foreach ($pickOrderAll['array'] as $val){
                $inventoryAll = find(array(
                    'table' => 'inventory_detail',
                    'where' => "sourceId = '$val[id]' and num >0 and coid = '" . self::$coid . "'"
                ));
                foreach ($inventoryAll['array'] as $item) {
                    $pickNum += machiningOrderClass::material_num_change($item['materialId'], $item['unit'], $material['unit'], $item['num']);
                }
            }
            $pickNum = round($pickNum,2);
            //退料
            $refundNum=0;
            $refundOrderAll = find(array(
                'table'=>'pick_order as a join pick_order_detail as b on a.id = b.orderId',
                "where"=>"a.state = '已确认' and a.type=1 and b.materialId = '$array[materialId]'"
            ));
            foreach ($refundOrderAll['array'] as $val){
                $inventoryAll = find(array(
                    'table' => 'inventory_detail',
                    'where' => "sourceId = '$val[id]' and num >0 and coid = '" . self::$coid . "'"
                ));
                foreach ($inventoryAll['array'] as $item) {
                    $refundNum += machiningOrderClass::material_num_change($item['materialId'], $item['unit'], $material['unit'], $item['num']);
                }
            }
            $refundOrderAll = find(array(
                'table'=>'pick_order as a join pick_order_detail as b on a.id = b.orderId',
                "where"=>"a.state = '已确认' and a.type=1 and b.materialId = '$array[materialId]'"
            ));
            foreach ($refundOrderAll['array'] as $val){
                $refundNum+=machiningOrderClass::material_num_change($val['materialId'],$val['unit'],$material['unit'],$val['num']);
            }
            $refundNum = round($refundNum,2);

            //配料
            $disNum=0;
            $all = find(array(
                'table'=>'material_distribute_num as a join material_distribute as b on a.orderId = b.id',
                'field'=>"a.*",
                'where'=>"b.state = '已确认' and a.materialId = '$array[materialId]' "
            ));
            foreach ($all['array'] as $val){
                $disNum+=machiningOrderClass::material_num_change($val['materialId'],$val['unit'],$material['unit'],$val['num']);
            }
            $actual = $pickNum+$disNum-$refundNum;   //实际用量
            $over = round($actual-$array['quantity'],2);  //差异
            $comparison = $actual>$max?$actual:$max;
            $estimateWidth = $max>0?round($array['quantity']/$comparison*138):0;
            $actualWidth = $max>0?round($actual/$comparison*138):0;
            $array['quantity'] = self::lostZero($array['quantity'],'numPrecision');  //实际用量
            $li .= "<li>
                    <p class='material-name'><span class='m-name' title='".($i+1)." {$material['code']}-{$material['name']}'>".($i+1)." {$material['code']}-{$material['name']}</span><span class='difference'>{$over}</span></p>
                    <div class='consumption-situation'>
                        <p><span class='progress-text'>{$array['quantity']}</span><progress value='{$actual}' max='{$array['quantity']}' style='width: {$estimateWidth}px;'></progress></p>
                        <!--<p><span class='progress-text'>{$actual}</span><progress value='{$actual}' max='{$actual}' style='width: {$actualWidth}px;'></progress></p>-->
                    </div>
                </li>";
        }
        $style = count((array)$arr['array'])<9?" style='display: none;' ":"";
        $material_consumption = "
            <div class='yield' id='material_box'>
                <ul id='material1'>
                    {$li}
                </ul>
                <ul id='material2' $style></ul>
            </div>
            ";
        //计时计件
        $li = "";
        $month = date("Y-m");  //当月
        $staff = find(array(
            "table"=>"team_detail",
            "field"=>"stid",
            "where"=>" 1=1 and coid = '".self::$coid."' group by stid "
        ));
        foreach ($staff['array'] as $i => $val) {
            $st = query("staff"," stid = '$val[stid]' ","name");
            $pieceMoney = 0;
            $timeMoney = 0;
            $PCS = 0;
            $hour = 0;
            //计件工资
            $piece = find(array(
                "table"=>"process_report_staff as a join process_report as b on a.orderId = b.id",
                "field"=>"b.*,a.stid as teamStid",
                "where"=>" b.coid = '".self::$coid."' and b.state = '已确认' and b.classify = '工序报工' and a.stid = '$val[stid]' and date_format(teamNo,'%Y-%m') = '$month' "
            ));
            foreach ((array)$piece['array'] as $array){
                $material = query('material',"id = '$array[materialId]'");
                $array['yield'] = machiningOrderClass::material_num_change($array['materialId'],$array['unit'],$material['unit'],$array['yield']);
                $PCS += $array['yield'];
                /*$routMx = query('routing_detail',"id = '$array[routingMxId]'");
                $routMx['price']=$routMx['price']?:0;
                $salary = round($routMx['price']*$array['yield'],2);

                if ($array['valuationType'] =='个人计件'){
                    $personMoney = $salary;
                }else{
                    $team_detail = query('team_detail',"orderId = '$array[teamId]' and stid = '$array[teamStid]'");
                    $team_detail['rate'] = $team_detail['rate']?:0;
                    //当前班组人员考勤
                    $workshop_clock_detail = find(array('table'=>'workshop_clock as a join workshop_clock_detail as b on a.id = b.orderId','single'=>"a.state !='草稿' and a.teamId like '%$array[teamId]%' and b.stid = '$array[teamStid]' and b.recordDate = '$array[teamNo]'",'field'=>"b.hour"));
                    $workshop_clock_detail['hour'] = $workshop_clock_detail['hour']??0;
                    $rateSum = $this->caculate($array['teamId'],$array['teamNo']);
                    //公式  计件工资*（个人计件系数*个人考勤）/(班组中每个人的(个人考勤*个人系数)之和)
                    $personMoney =$rateSum>0? round($salary*($team_detail['rate']*$workshop_clock_detail['hour']/$rateSum),2):0;
                }
                $pieceMoney += $personMoney;*/
            }
            //计时工资
            $time = find(array(
                "table"=>"timing_report",
                "field"=>"distinct recordDate,teamId,staffId",
                "where"=>" coid = '".self::$coid."' and staffId = '$val[stid]' and date_format(recordDate,'%Y-%m') = '$month' "
            ));
            foreach ((array)$time['array'] as $array){
                $hour += find(array(
                    'table'=>'timing_report',
                    'where'=>"recordDate = '$array[recordDate]' and teamId = '$array[teamId]' and staffId = '$array[staffId]' and coid = '".self::$coid."'",
                    'sum'=>"hour"
                ));
                /*$teamMx = query('team_detail',"orderId = '$array[teamId]' and stid = '$array[staffId]'");
                $timeMoney += round($hour*$teamMx['price'],2);*/
            }
            $li .= "<li>
                    <span>" . ($i + 1) . "</span>
                    <span>{$st['name']}</span>
                    <span>" . $PCS . "</span>
                    <span>" . $hour . "</span>
                </li>";
        }
        $style = count((array)$staff['array'])<13?" style='display: none;' ":"";
        $timePiece = "
            <p class='piece-title'><span>序号</span><span>员工</span><span>计件（PCS）</span><span>计时（h）</span></p>
            <div class='yield' id='time_piece_box'>
                <ul id='timePiece1'>
                    {$li}
                </ul>
                <ul id='timePiece2' $style></ul>
            </div>
            ";
        //制造费用
        $month = date("Y-m");
        $lastYearDate = date("Y-m", strtotime("-1 year"));
        $lastMonthDate = date("Y-m", strtotime('-1 month'));
        $cost = find(array(
            "table"=>"cost_allocation_item as a left join cost_allocation as b on a.orderId = b.id",
            "field"=>"a.item,IFNULL(sum(a.money),0) as money",
            "where"=>" a.coid = '".self::$coid."' and b.state = '已确认' and date_format(b.recordDate,'%Y-%m') = '$month' group by a.item  "
        ));
        $li = "";
        foreach ((array)$cost['array'] as $i=>$array){
            $lastYear = find([
                    'table'  => "cost_allocation_item as a left join cost_allocation as b on a.orderId = b.id",
                    'field'  => "IFNULL(sum(a.money),0) as money",
                    'single' => " a.coid = '".self::$coid."' and b.state = '已确认' and date_format(b.recordDate,'%Y-%m') = '".$lastYearDate."' and a.item = '$array[item]' ",
                ])['money'] ?? 0;
            $lastMonth = find([
                    'table'  => "cost_allocation_item as a left join cost_allocation as b on a.orderId = b.id",
                    'field'  => "IFNULL(sum(a.money),0) as money",
                    'single' => " a.coid = '".self::$coid."' and b.state = '已确认' and date_format(b.recordDate,'%Y-%m') = '$lastMonthDate' and a.item = '$array[item]' ",
                ])['money'] ?? 0;
            $tb = $lastYear>0?round($array['money']/$lastYear,2)*100:0;
            $hb = $lastMonth>0?round($array['money']/$lastMonth,2)*100:0;
            $li .= "<li>
                    <span>".($i+1)."</span>
                    <span>间接材料</span>
                    <span>".$array['money']."</span>
                    <span>".$tb."%</span>
                    <span>".$hb."%</span>
                </li>";
        }
        $style = count((array)$cost['array'])<9?" style='display: none;' ":"";
        $makeCost = "
            <p class='make-title'><span>序号</span><span>费用项目</span><span>本期</span><span>同比</span><span>环比</span></p>
            <div class='yield' id='make_cost_box'>
                <ul id='makeCost1'>
                    {$li}
                </ul>
                <ul id='makeCost2' $style></ul>
            </div>
            ";
        $logoConrol = img('logoConrolImg');
        $html = <<<EOT
    <div id="base" class="">

      <!-- Unnamed (矩形) -->
      <div id="u0" class="ax_default box_1">
        <div id="u0_div" class=""></div>
        <div id="u0_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (图像) -->
      <div id="u1" class="ax_default _图片_">
        <img id="u1_img" class="img " src="{$this->root}img/dataBack/u1.jpg">
        <div id="u1_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u2" class="ax_default box_1">
        <div id="u2_div" class=""></div>
        <div id="u2_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (SVG) -->
      <div id="u3" class="ax_default _图片_">
        <img id="u3_img" class="img " src="$logoConrol">
        <div id="u3_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u4" class="ax_default _一级标题">
        <div id="u4_div" class=""></div>
        <div id="u4_text" class="text ">
          <p><span style="text-decoration:none;">生产看板</span></p>
        </div>
      </div>
      
      <!-- Unnamed (SVG) -->
      <div id="ufull" class="ax_default _图片_">
        <a href="{$this->root}control/adIndex.html?cla=productionKanban&fun=home" target="_blank"><img id="ufull_img" class="img " src="{$this->root}img/svg/full_screen.svg"></a>
        <div id="ufull_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (动态面板) -->
      <div id="u5" class="ax_default">
       <div id="u5_state1" class="panel_state" data-label="State2" style="visibility: inherit; position: relative;">
          <div id="u5_state1_content" class="panel_state_content">

            <!-- time (矩形) -->
            <div id="u7" class="ax_default _三级标题" data-label="time">
              <div id="u7_div" class=""></div>
              <div id="u7_text" class="text " style="visibility: inherit;">
                <p id="cache2"><span style="text-decoration:none;" id="showTime">2021-01-11 09:41:00 MONDAY</span></p>
              </div>
            </div>
          </div>
        </div></div>

      <!-- Unnamed (矩形) -->
      <div id="u8" class="ax_default box_1">
        <div id="u8_div" class=""></div>
        <div id="u8_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u9" class="ax_default box_1">
        <div id="u9_div" class=""></div>
        <div id="u9_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>
      
      <div id="u201" class="ax_default" style="width: 422px; height: 306px;">
        {$makeCost}
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u10" class="ax_default box_1">
        <div id="u10_div" class=""></div>
        <div id="u10_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u11" class="ax_default box_1">
        <div id="u11_div" class=""></div>
        <div id="u11_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u12" class="ax_default box_1">
        <div id="u12_div" class=""></div>
        <div id="u12_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u13" class="ax_default box_1">
        <div id="u13_div" class=""></div>
        <div id="u13_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u14" class="ax_default _三级标题">
        <div id="u14_div" class=""></div>
        <div id="u14_text" class="text ">
          <p><span style="text-decoration:none;">计划产量</span></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u15" class="ax_default _三级标题">
        <div id="u15_div" class=""></div>
        <div id="u15_text" class="text ">
          <p><span style="text-decoration:none;" class="quantity">{$totalPlan}</span></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u16" class="ax_default _三级标题">
        <div id="u16_div" class=""></div>
        <div id="u16_text" class="text ">
          <p><span style="text-decoration:none;">完成产量</span></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u17" class="ax_default _三级标题">
        <div id="u17_div" class=""></div>
        <div id="u17_text" class="text ">
          <p><span style="text-decoration:none;" class="quantity">{$totalYield}</span></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u18" class="ax_default _三级标题">
        <div id="u18_div" class=""></div>
        <div id="u18_text" class="text ">
          <p><span style="text-decoration:none;">完成率</span></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u19" class="ax_default _三级标题">
        <div id="u19_div" class=""></div>
        <div id="u19_text" class="text ">
          <p style="font-size:14px;"><span style="font-size:28px;text-decoration:none;" class="quantity">{$completionRate}</span><span style="text-decoration:none;">%</span></p>
        </div>
      </div>

      <!-- Unnamed (垂直线) -->
      <div id="u20" class="ax_default line">
        <img id="u20_img" class="img " src="{$this->root}img/dataBack/u20.svg">
        <div id="u20_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (垂直线) -->
      <div id="u21" class="ax_default line">
        <img id="u21_img" class="img " src="{$this->root}img/dataBack/u20.svg">
        <div id="u21_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u22" class="ax_default _三级标题">
        <div id="u22_div" class=""></div>
        <div id="u22_text" class="text ">
          <p><span style="text-decoration:none;">班组产量</span></p>
        </div>
      </div>

      <!-- Unnamed (动态面板) -->
      <div id="review_box" class="ax_default">
        {$team_yield}
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u36" class="ax_default box_1">
        <div id="u36_div" class=""></div>
        <div id="u36_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u37" class="ax_default _三级标题">
        <div id="u37_div" class=""></div>
        <div id="u37_text" class="text ">
          <p><span style="text-decoration:none;">产线生产进度</span></p>
        </div>
      </div>

      <!-- Unnamed (动态面板) -->
      <div style='transition: 0.8s;'  id='line_progress' class="ax_default">
        {$line_progress}
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u79" class="ax_default _三级标题">
        <div id="u79_div" class=""></div>
        <div id="u79_text" class="text ">
          <p><span style="text-decoration:none;">订单完成情况</span></p>
        </div>
      </div>
      
      <div id="delayHtml" class="ax_default _图片_">
        
      </div>
      <div id="onScheduleHtml" class="ax_default _图片_">
      
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u80" class="ax_default _三级标题">
        <div id="u80_div" class=""></div>
        <div id="u80_text" class="text ">
          <p><span style="text-decoration:none;">材料耗用</span></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u81" class="ax_default _三级标题">
        <div id="u81_div" class=""></div>
        <div id="u81_text" class="text ">
          <p><span style="text-decoration:none;">计时计件</span></p>
        </div>
      </div>
      
      <div id="u318" class="ax_default" style="width: 385px; height: 470px;">
        {$timePiece}
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u82" class="ax_default _三级标题">
        <div id="u82_div" class=""></div>
        <div id="u82_text" class="text ">
          <p><span style="text-decoration:none;">制造费用</span></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u83" class="ax_default _三级标题">
        <div id="u83_div" class=""></div>
        <div id="u83_text" class="text ">
          <p style="font-size:11px;"><span style="font-size:16px;text-decoration:none;">产量波动&nbsp; &nbsp; </span><span style="text-decoration:none;"></span></p>
        </div>
      </div>

      <!-- Unnamed (动态面板) -->
      <div id="yieldWaveHtml" class="ax_default">
        
      </div>

      <!-- Unnamed (动态面板) -->
      <div id="u201" class="ax_default" style="width: auto; height: auto;">
      </div>

      <!-- Unnamed (组合) -->
      <div id="u451" class="ax_default" data-left="1225" data-top="166" data-width="190" data-height="190">
        <!-- Unnamed (动态面板) -->
        <div id="u453" class="ax_default">
            <div style='transition: 0.8s;' id='pieTextActual'><p class='actual-name'></p><p class='actual-rate'></p></div>
            <div id="categoryActualHtml"></div>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u480" class="ax_default _三级标题">
        <div id="u480_div" class=""></div>
        <div id="u480_text" class="text ">
          <p><span style="text-decoration:none;">分类占比-实际耗用</span></p>
        </div>
      </div>

      <!-- Unnamed (组合) -->
      <div id="u481" class="ax_default" data-left="1225" data-top="454" data-width="190" data-height="190">
        <!-- Unnamed (动态面板) -->
        <div id="u483" class="ax_default">
            <div style='transition: 0.8s;' id='pieTextExceed'><p class='exceed-name'></p><p class='exceed-rate'></p></div>
            <div id="categoryExceedHtml" class="ax_default">
            </div>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u510" class="ax_default _三级标题">
        <div id="u510_div" class=""></div>
        <div id="u510_text" class="text ">
          <p><span style="text-decoration:none;">分类占比-超耗</span></p>
        </div>
      </div>

      <!-- Unnamed (动态面板) -->
      <div id="u511" class="ax_default">
        {$material_consumption}
      </div>
    </div>
    <script src='{$this->root}static/javascript/echarts.min.js'></script>
    <script>
        
        $(document).ready(function(){
            //计时器
            var timer = null;
            timer = setTimeout(time, 1000);
            function time() {
                clearTimeout(timer);
                dt = new Date();
                var y = dt.getFullYear();
                var mt = dt.getMonth() + 1;
                var day = dt.getDate();
                var wi = dt.getDay()
                var h = dt.getHours();
                var m = dt.getMinutes();
                var s = dt.getSeconds();
                const weeks = [ 'SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY']
                const fullTime =  [y, mt, day].map(formatNumber).join('-') + ' ' + [h, m, s].map(formatNumber).join(':') + ' ' + weeks[wi]
                document.getElementById("showTime").innerHTML = fullTime;
                timer = setTimeout(time, 1000);
            }
            const formatNumber = n => {
                n = n.toString()
                return n[1] ? n : '0' + n
            }
            //滚动方法
            var timerRool = []
            
            function roll(t,id1,id2,box,timer){
               var ul1 = document.getElementById(id1);
                var ul2 = document.getElementById(id2);
                var ulbox = document.getElementById(box);
                ul2.innerHTML = ul1.innerHTML;
                ulbox.scrollTop = 0;
                rollStart(t,id1,id2,box,timer);
            }
            function rollStart(t,id1,id2,box,timer){
               var ul1 = document.getElementById(id1);
                var ul2 = document.getElementById(id2);
                var ulbox = document.getElementById(box);
                rollStop(timer);
                timerRool[timer] = setInterval(()=>{
                    const radios = parseFloat((1 / window.devicePixelRatio).toFixed(2)) + 0.01;//兼容到浏览器页面百分比缩小时也能自动滚动；
                    // 当滚动高度大于列表内容高度时恢复为0
                    if (ulbox.scrollTop >= ul1.scrollHeight) {
                        ulbox.scrollTop = 0;
                    } else {
                        ulbox.scrollTop = ulbox.scrollTop + radios;
                    }
                }, t);
            }
            function rollStop(timer){
               clearInterval(timerRool[timer]);
            }
            //产量滚动播放
            roll(60,'comment1','comment2','review_box','yield')
            $("#review_box").mouseout(function(){
              rollStart(60,'comment1','comment2','review_box','yield')
            });
            $("#review_box").mouseover(function(){
              rollStop('yield')
            });
            //材料耗用滚动
            roll(60,'material1','material2','material_box','material')
            $("#material_box").mouseout(function(){
              rollStart(60,'material1','material2','material_box','material')
            });
            $("#material_box").mouseover(function(){
              rollStop('material')
            });
            //计时计件
            roll(60,'timePiece1','timePiece2','time_piece_box','piece')
            $("#time_piece_box").mouseout(function(){
              rollStart(60,'timePiece1','timePiece2','time_piece_box','piece')
            });
            $("#time_piece_box").mouseover(function(){
              rollStop('piece')
            });
            //制造费用
            roll(60,'makeCost1','makeCost2','make_cost_box','cost')
            $("#make_cost_box").mouseout(function(){
              rollStart(60,'makeCost1','makeCost2','make_cost_box','cost')
            });
            $("#make_cost_box").mouseover(function(){
              rollStop('cost')
            });
            //翻转
            var id=document.getElementById("line_progress");
            
            var x = 2
            var transform = setInterval(function(){
                setTimeout(function () {
                    $.post(root + "control/adIndex.html?cla=productionKanban&fun=lineData", {page:x}, function (data) {
                        x = data.nextPage
                        $("#comment3").html(data.html);
                    }, "json");
                }, 30000);
            }, 30000)
        })
        function search_line(form,cla,fun) {
            $("#" + fun + "Html").html("数据查询中，请稍后。。。");
            //串联表单
            var formName = form.split(",");
            var serialize = "";
            var a = "";
            for (var i = 0; i < formName.length; i++) {
                if (serialize == "") {
                    a = "";
                } else {
                    a = "&";
                }
                if (formName[i] != "") {
                    serialize += a + $("[name=" + formName[i] + "]").serialize();
                }
            }
            $.post(root + "control/adIndex.html?cla=" + cla + "&fun=" + fun, serialize, function (data) {
                 $("#" + fun + "Html").html(data.html);
            }, "json");
        }
        $(function() {
            search_line('mainForm','productionKanban', 'delay')
            search_line('mainForm','productionKanban','onSchedule');
            search_line('mainForm','productionKanban','yieldWave');
            
            $.post(root + "control/adIndex.html?cla=productionKanban&fun=categoryActual", {page:1}, function (data) {
                $("#pieTextActual").find(".actual-name").html(data.name);
                $("#pieTextActual").find(".actual-rate").html(data.rate);
                $("#categoryActualHtml").html(data.html);
            }, "json");
            $.post(root + "control/adIndex.html?cla=productionKanban&fun=categoryExceed", {page:1}, function (data) {
                $("#pieTextExceed").find(".exceed-name").html(data.name);
                $("#pieTextExceed").find(".exceed-rate").html(data.rate);
                $("#categoryExceedHtml").html(data.html);
            }, "json");
            setInterval(function(){
                setTimeout(function () {
                    //分类占比-实际耗用翻转
                    var id=document.getElementById("pieTextActual");
                    var x = 2
                    $.post(root + "control/adIndex.html?cla=productionKanban&fun=categoryActual", {page:x}, function (data) {
                        x = data.nextPage
                        $("#pieTextActual").find(".actual-name").html(data.name);
                        $("#pieTextActual").find(".actual-rate").html(data.rate);
                        $("#categoryActualHtml").html(data.html);
                    }, "json");
                    
                    //本月翻转
                    var id2=document.getElementById("pieTextExceed");
                    var y = 2
                    $.post(root + "control/adIndex.html?cla=productionKanban&fun=categoryExceed", {page:x}, function (data) {
                        y = data.nextPage
                        $("#pieTextExceed").find(".exceed-name").html(data.name);
                        $("#pieTextExceed").find(".exceed-rate").html(data.rate);
                        $("#categoryExceedHtml").html(data.html);
                    }, "json");
                }, 30000);
            }, 30000)
        })
        
    </script>
EOT;

        return head("ad") . $this->style() . $html . warn() . $this->adfooter();
    }

    /**
     * 延期率
     */
    public function delay(): bool|string
    {
        //订单完成情况
        $timeArr[0] = date('Y-m-d',strtotime("-6 day"));
        $timeArr[1] = $this->date;
        $m = $timeArr[0];
        $res   = [];
        while($m <= $timeArr[1]) {
            $overdueNum = 0;
            $order = find(array(
                "table"=>"machining_order_mx as a join machining_order as b on a.orderId = b.id",
                "field"=>"a.id,b.endDate",
                "where"=>" b.coid = '".self::$coid."' and b.state = '已确认' and date_format(b.recordDate, '%Y-%m-%d') = '$m' "
            ));  //总订单
            foreach ((array)$order['array'] as $array){
                //最后入库日期
                $last = find(array(
                    'table'=>'inventory_detail as a join inventory as b on a.orderId = b.id',
                    'field'=>"date(b.time) as lastDate",
                    'single'=>"a.sourceId in (select id from machining_in_order_detail where sourceId = '$array[id]')"
                ));
                //已入库数量
                $in_num = find(array(
                    'table'=>'inventory_detail',
                    'where'=>"sourceId in (select id from machining_in_order_detail where sourceId = '$array[id]')",
                    'sum'=>"num"
                ));
                //总的待入库数量
                $all_in_num = find(array(
                    'table'=>'inventory_detail',
                    'where'=>"sourceId in (select id from machining_in_order_detail where sourceId = '$array[id]')",
                    'sum'=>"orderNum"
                ));
                $state = '待入库';
                if ($all_in_num > $in_num && $in_num >0){
                    $state = '部分入库';
                }elseif($in_num == $all_in_num && $in_num >0){
                    $state = '已入库';
                }
                $last['lastDate'] = isset($last['lastDate'])?$last['lastDate']:'';
                if(($state != '已入库' && $this->date > $array['endDate']) || (!empty($last['lastDate']) && $last['lastDate'] > $array['endDate'])){
                    $overdueNum ++;
                }
            }
            $rate = count((array)$order['array'])>0?round($overdueNum/count((array)$order['array']),2)*100:0;
            $res[] = [
                'date' => date("m月d日",strtotime($m)),
                'rate' => $rate,
            ];
            $m = date("Y-m-d",strtotime($m." +1 day"));
        }
        $data = [
            "subtext" => '',
            "name" => array_column($res,'date'),
            "legendStyle" => "textStyle: {
				    color: '#8c8c8c'
				}",
            "series" => [
                [
                    'name' => '延期率',
                    'smooth' => true,
                    'itemStyle' => json_encode(['color' => '#5b8ff9'], 320),
                    'data' => array_column($res,'rate')
                ]
            ]
        ];
        $qualityKanbanClass = new qualityKanbanClass();
        $json['html'] = $qualityKanbanClass->curveQuality($data);
        return json_encode($json, 320);
    }
    /**
     * 按时完成情况
     */
    public function onSchedule(): bool|string
    {
        $timeArr[0] = date('Y-m-d',strtotime("-6 day"));
        $timeArr[1] = $this->date;
        $m = $timeArr[0];
        $res   = [];
        while($m <= $timeArr[1]) {
            $onSchedule = 0;
            $overdue = 0;
            $order = find(array(
                "table"=>"machining_order_mx as a join machining_order as b on a.orderId = b.id",
                "field"=>"a.id,b.endDate",
                "where"=>" b.coid = '".self::$coid."' and b.state = '已确认' and date_format(b.recordDate, '%Y-%m-%d') = '$m' "
            ));  //总订单
            foreach ((array)$order['array'] as $array){
                //最后入库日期
                $last = find(array(
                    'table'=>'inventory_detail as a join inventory as b on a.orderId = b.id',
                    'field'=>"date(b.time) as lastDate",
                    'single'=>"a.sourceId in (select id from machining_in_order_detail where sourceId = '$array[id]')"
                ));
                //已入库数量
                $in_num = find(array(
                    'table'=>'inventory_detail',
                    'where'=>"sourceId in (select id from machining_in_order_detail where sourceId = '$array[id]')",
                    'sum'=>"num"
                ));
                //总的待入库数量
                $all_in_num = find(array(
                    'table'=>'inventory_detail',
                    'where'=>"sourceId in (select id from machining_in_order_detail where sourceId = '$array[id]')",
                    'sum'=>"orderNum"
                ));
                $state = '待入库';
                if ($all_in_num > $in_num && $in_num >0){
                    $state = '部分入库';
                }elseif($in_num == $all_in_num && $in_num >0){
                    $state = '已入库';
                }
                $last['lastDate'] = isset($last['lastDate'])?$last['lastDate']:'';
                //按时
                if($state == '已入库' && $last['lastDate'] < $array['endDate']){
                    $onSchedule ++;
                //延期
                }elseif(($state != '已入库' && $this->date > $array['endDate']) || (!empty($last['lastDate']) && $last['lastDate'] > $array['endDate'])){
                    $overdue ++;
                }
            }

            $res[] = [
                'date' => date("m月d日",strtotime($m)),
                'onSchedule' => $onSchedule,
                'overdue' => $overdue,
            ];
            $m = date("Y-m-d",strtotime($m." +1 day"));
        }
        $data = [
            "subtext" => '',
            "name" => array_column($res,'date'),
            "legendStyle" => "textStyle: {
				    color: '#8c8c8c'
				}",
            "series" => [
                [
                    'name' => '按期完成',
                    'stack' => 'value',
                    'itemStyle' => json_encode(['color'=>'#464a66'],320),
                    'emphasis' => json_encode(['focus'=>'series']),
                    'data' => array_column($res,'onSchedule')
                ],
                [
                    'name' => '延期',
                    'stack' => 'value',
                    'itemStyle' => json_encode(['color'=>'#5b8ff9'],320),
                    'emphasis' => json_encode(['focus'=>'series']),
                    'data' => array_column($res,'overdue')
                ],
            ]
        ];
        $qualityKanbanClass = new qualityKanbanClass();
        $json['html'] = $qualityKanbanClass->curveQuality($data, 'bar');
        return json_encode($json, 320);
    }

    /**
     * 分类占比-实际耗用 - 返回数据
     */
    public function categoryActual(): bool|string
    {
        $month = date("Y-m");  //and date_format(b.recordDate, '%Y-%m') = '$month'
        $page = $this->post('page')?:1;
        $sqlFirst = ($page - 1) * 1;
        //查询当前分类
        $data = find(array(
            "table"=>"machining_order_detail as a join machining_order as b on a.orderId = b.id join material as c on c.id = a.materialId",
            "field"=>"c.typeId",
            "where"=>" a.coid = '".self::$coid."' and b.state = '已确认' group by c.typeId order by c.typeId desc limit {$sqlFirst},1 "
        ));
        $nextPage = $page+1;
        if(empty($data['array'])){
            $data = find(array(
                "table"=>"machining_order_detail as a join machining_order as b on a.orderId = b.id join material as c on c.id = a.materialId",
                "field"=>"c.typeId",
                "where"=>" a.coid = '".self::$coid."' and b.state = '已确认' group by c.typeId order by c.typeId desc limit 0,1 "
            ));
            $nextPage = 2;
        }
        $name = "";
        $proportion = 0;
        $other = 100;
        if(isset($data['array'][0]['typeId'])) {
            $material_type = query("material_type", " id = '{$data['array'][0]['typeId']}' ");
            $name = $material_type['name'];
            //查询总得实际耗用
            $page = find(array(
                "table"=>"machining_order_detail as a join machining_order as b on a.orderId = b.id join material as c on c.id = a.materialId",
                "field"=>"a.*,b.orderNo,date(b.time) as recordDate,b.lineId,b.type,c.code,c.name as materialName,c.model,c.typeId",
                "where"=>" a.coid = '".self::$coid."' and b.state = '已确认' "
            ));
            $total = 0;
            $typeTotal = 0;
            foreach ((array)$page['array'] as $array) {
                //领料
                $pickNum=0;
                $pickOrderAll = find(array(
                    'table'=>'pick_order as a join pick_order_detail as b on a.id = b.orderId',
                    "where"=>"a.state = '已确认' and a.type=0 and b.sourceId = '$array[id]' and b.materialId = '$array[materialId]'"
                ));
                foreach ($pickOrderAll['array'] as $val){
                    $inventoryAll = find(array(
                        'table' => 'inventory_detail',
                        'where' => "sourceId = '$val[id]' and num >0 and coid = '" . self::$coid . "'"
                    ));
                    foreach ($inventoryAll['array'] as $item) {
                        $pickNum += machiningOrderClass::material_num_change($array['materialId'], $item['unit'], $array['unit'], $item['num']);
                    }
                }
                $pickNum = round($pickNum,2);
                //退料
                $refundNum=0;
                $refundOrderAll = find(array(
                    'table'=>'pick_order as a join pick_order_detail as b on a.id = b.orderId',
                    "where"=>"a.state = '已确认' and a.type=1 and b.sourceId = '$array[id]' and b.materialId = '$array[materialId]'"
                ));
                foreach ($refundOrderAll['array'] as $val){
                    $inventoryAll = find(array(
                        'table' => 'inventory_detail',
                        'where' => "sourceId = '$val[id]' and num >0 and coid = '" . self::$coid . "'"
                    ));
                    foreach ($inventoryAll['array'] as $item) {
                        $refundNum += machiningOrderClass::material_num_change($array['materialId'], $item['unit'], $array['unit'], $item['num']);
                    }
                }
                $refundOrderAll = find(array(
                    'table'=>'pick_order as a join pick_order_detail as b on a.id = b.orderId',
                    "where"=>"a.state = '已确认' and a.type=1 and b.sourceId in (select id from pick_order_detail where sourceId = '$array[id]') and b.materialId = '$array[materialId]'"
                ));
                foreach ($refundOrderAll['array'] as $val){
                    $refundNum+=machiningOrderClass::material_num_change($array['materialId'],$val['unit'],$array['unit'],$val['num']);
                }
                $refundNum = round($refundNum,2);

                //配料
                $disNum=0;
                $all = find(array(
                    'table'=>'material_distribute_num as a join material_distribute as b on a.orderId = b.id',
                    'field'=>"a.*",
                    'where'=>"b.state = '已确认' and a.materialId = '$array[materialId]' and machiningOrderMxId = '$array[targetSkuId]'"
                ));
                foreach ($all['array'] as $val){
                    $disNum+=machiningOrderClass::material_num_change($array['materialId'],$val['unit'],$array['unit'],$val['num']);
                }
                $total +=$pickNum+$disNum-$refundNum;
                if($array['typeId'] == $material_type['id']){
                    $typeTotal += $pickNum+$disNum-$refundNum;
                }
            }
            $proportion = $total>0?round($typeTotal/$total,2)*100:0;
            $other = 100-$proportion;
        }
        //金额占比
        $series = [
            ['name' => '', 'data' => $proportion],
            ['name' => '', 'data' => $other]
        ];
        $data         = [
            "text" => '',
            "subtext" => '',
            "color" => ['#5b8ff9','#464a66'],
            "series" => $series,
        ];
        $json['html'] = $this->pie($data);
        $json['name'] = $name;
        $json['rate'] = $proportion.'%';
        $json['nextPage'] = $nextPage;
        return json_encode($json, 320);
    }
    /**
     * 分类占比-超耗 - 返回数据
     */
    public function categoryExceed(): bool|string
    {
        $month = date("Y-m"); // and date_format(b.recordDate, '%Y-%m') = '$month'
        $page = $this->post('page')?:1;
        $sqlFirst = ($page - 1) * 1;
        //查询当前分类
        $data = find(array(
            "table"=>"machining_order_detail as a join machining_order as b on a.orderId = b.id join material as c on c.id = a.materialId",
            "field"=>"c.typeId",
            "where"=>" a.coid = '".self::$coid."' and b.state = '已确认' group by c.typeId order by c.typeId desc limit {$sqlFirst},1 "
        ));
        $nextPage = $page+1;
        if(empty($data['array'])){
            $data = find(array(
                "table"=>"machining_order_detail as a join machining_order as b on a.orderId = b.id join material as c on c.id = a.materialId",
                "field"=>"c.typeId",
                "where"=>" a.coid = '".self::$coid."' and b.state = '已确认' group by c.typeId order by c.typeId desc limit 0,1 "
            ));
            $nextPage = 2;
        }
        $name = "";
        $proportion = 0;
        $other = 100;
        if(isset($data['array'][0]['typeId'])) {
            $material_type = query("material_type", " id = '{$data['array'][0]['typeId']}' ");
            $name = $material_type['name'];
            //查询总得实际耗用
            $page = find(array(
                "table"=>"machining_order_detail as a join machining_order as b on a.orderId = b.id join material as c on c.id = a.materialId",
                "field"=>"a.*,b.orderNo,date(b.time) as recordDate,b.lineId,b.type,c.code,c.name as materialName,c.model,c.typeId",
                "where"=>" a.coid = '".self::$coid."' and b.state = '已确认' "
            ));
            $total = 0;
            $typeTotal = 0;
            foreach ((array)$page['array'] as $array) {
                //领料
                $pickNum=0;
                $pickOrderAll = find(array(
                    'table'=>'pick_order as a join pick_order_detail as b on a.id = b.orderId',
                    "where"=>"a.state = '已确认' and a.type=0 and b.sourceId = '$array[id]' and b.materialId = '$array[materialId]'"
                ));
                foreach ($pickOrderAll['array'] as $val){
                    $inventoryAll = find(array(
                        'table' => 'inventory_detail',
                        'where' => "sourceId = '$val[id]' and num >0 and coid = '" . self::$coid . "'"
                    ));
                    foreach ($inventoryAll['array'] as $item) {
                        $pickNum += machiningOrderClass::material_num_change($array['materialId'], $item['unit'], $array['unit'], $item['num']);
                    }
                }
                $pickNum = round($pickNum,2);
                //退料
                $refundNum=0;
                $refundOrderAll = find(array(
                    'table'=>'pick_order as a join pick_order_detail as b on a.id = b.orderId',
                    "where"=>"a.state = '已确认' and a.type=1 and b.sourceId = '$array[id]' and b.materialId = '$array[materialId]'"
                ));
                foreach ($refundOrderAll['array'] as $val){
                    $inventoryAll = find(array(
                        'table' => 'inventory_detail',
                        'where' => "sourceId = '$val[id]' and num >0 and coid = '" . self::$coid . "'"
                    ));
                    foreach ($inventoryAll['array'] as $item) {
                        $refundNum += machiningOrderClass::material_num_change($array['materialId'], $item['unit'], $array['unit'], $item['num']);
                    }
                }
                $refundOrderAll = find(array(
                    'table'=>'pick_order as a join pick_order_detail as b on a.id = b.orderId',
                    "where"=>"a.state = '已确认' and a.type=1 and b.sourceId in (select id from pick_order_detail where sourceId = '$array[id]') and b.materialId = '$array[materialId]'"
                ));
                foreach ($refundOrderAll['array'] as $val){
                    $refundNum+=machiningOrderClass::material_num_change($array['materialId'],$val['unit'],$array['unit'],$val['num']);
                }
                $refundNum = round($refundNum,2);

                //配料
                $disNum=0;
                $all = find(array(
                    'table'=>'material_distribute_num as a join material_distribute as b on a.orderId = b.id',
                    'field'=>"a.*",
                    'where'=>"b.state = '已确认' and a.materialId = '$array[materialId]' and machiningOrderMxId = '$array[targetSkuId]'"
                ));
                foreach ($all['array'] as $val){
                    $disNum+=machiningOrderClass::material_num_change($array['materialId'],$val['unit'],$array['unit'],$val['num']);
                }
                $over = round($pickNum+$disNum-$refundNum-$array['quantity'],2);
                if($over > 0) {
                    $total += $over;
                    if ($array['typeId'] == $material_type['id']) {
                        $typeTotal += $over;
                    }
                }
            }
            $proportion = $total>0?round($typeTotal/$total,2)*100:0;
            $other = 100-$proportion;
        }
        //金额占比
        $series = [
            ['name' => '', 'data' => $proportion],
            ['name' => '', 'data' => $other]
        ];
        $data         = [
            "text" => '',
            "subtext" => '',
            "color" => ['#5b8ff9','#464a66'],
            "series" => $series,
        ];
        $json['html'] = $this->pie($data);
        $json['name'] = $name;
        $json['rate'] = $proportion.'%';
        $json['nextPage'] = $nextPage;
        return json_encode($json, 320);
    }
    /**
     * 产量波动 - 返回数据
     */
    public function yieldWave(): bool|string
    {
        $timeArr[0] = date('Y-m-d',strtotime("-1 month"));
        $timeArr[1] = $this->date;
        $m = $timeArr[0];
        $res   = [];
        $max = 1;  //y轴最大数值
        while($m <= $timeArr[1]){
            $now = find([
                    'table'  => "process_report",
                    'field'  => "IFNULL(sum(yield),0) as num",
                    'single' => " coid = '".self::$coid."' and classify = '工序报工' and state = '已确认' and date_format(teamNo, '%Y-%m-%d') = '$m' ",
                ])['num'] ?? 0;
            $lastYearDate = date('Y-m-d',strtotime($m." -1 year"));
            $lastYear = find([
                    'table'  => "process_report",
                    'field'  => "IFNULL(sum(yield),0) as num",
                    'single' => " coid = '".self::$coid."' and classify = '工序报工' and state = '已确认' and date_format(teamNo, '%Y-%m-%d') = '$lastYearDate' ",
                ])['num'] ?? 0;
            $res[] = [
                'date'     => date("m月d日",strtotime($m)),
                'now' => $now,
                'lastYear' => $lastYear,
            ];
            //修改最大数值
            $big = $now>$lastYear?$now:$lastYear;
            $max = $big>$max?$big:$max;
            $m = date("Y-m-d",strtotime($m." +1 day"));
        }
        $data = [
            "subtext" => '',
            "name" => array_column($res,'date'),
            "ymax" => $max,
            "series" => [
                [
                    'name' => '当前',
                    'smooth' => true,
                    'itemStyle' => json_encode(['color'=>'#5b8ff9'],320),
                    'data' => array_column($res,'now')
                ],
                [
                    'name' => '去年周期',
                    'smooth' => true,
                    'itemStyle' => json_encode(['color'=>'#464a66'],320),
                    'data' => array_column($res,'lastYear')
                ]
            ]
        ];
        $json['html'] = $this->curveRool($data, 'area');
        return json_encode($json, 320);
    }

    /**
     * 曲线图模板
     *
     * @param array  $data = ["name" => "纵坐标标题一维数组", "series" => [ ["name" => "系列名称","data" => ["数据"] ],… ] ];
     * @param string $type 类型：折线 line ,柱状图 bar
     */
    public function curveRool(array $data, string $type = 'line')
    {
        $areaStyle = '';
        if ($type == 'area') {
            //面积曲线
            $type      = 'line';
            $areaStyle = "areaStyle:{},";
        }
        //系列
        $series = $legend = "";
        // 自定义
        $keys   = ['stack', 'emphasis', 'smooth', 'barMaxWidth', 'itemStyle', 'smooth'];
        $result = isset($data['series'][0]) ? array_intersect($keys, array_keys($data['series'][0])) : [];
        foreach ($data['series'] as $array) {
            $comma     = empty($series) ? '' : ',';
            $attribute = '';
            foreach ($result as $key) {
                if (isset($array[$key])) {
                    $attribute .= $key . ':' . (($key == 'emphasis' || $key == 'itemStyle') ? $array[$key] : "'$array[$key]'") . ',';
                }
            }
            $list_type = isset($array['type']) ? $array['type'] : $type;
            $series    .= $comma . "
			{
				name: '" . $array['name'] . "',
				type: '$list_type',
                $attribute
				data: [" . implode(",", $array['data']) . "],
				$areaStyle
			}";
            $legend    .= "'{$array['name']}',";
        }
        $yattr = "";
        //限制y轴数值
        if(isset($data['ymax'])){
            $yattr .= ",min: 0,max: ".$data['ymax'];
        }
        $legend = rtrim($legend, ',');
        $text = isset($data['text'])?$data['text']:'';
        $subtext = isset($data['subtext'])?$data['subtext']:'';
        //生成html
        $option = "
        var dd = ['" . implode("','", $data['name']) . "']
		var option = {
			title: {
                text: '{$text}',
                subtext: '{$subtext}',
                left: 'right',
                top: '0%'
            },
			tooltip: {
                trigger: 'axis'
            },
			legend: {
                top:'top',
                right:'5%',
				data: [" . $legend . "],
                textStyle: {
				    color: '#8c8c8c'
				}
			},
			grid: {
                left: '3%', right: '3%', bottom: '10%', containLabel: true
			},
			toolbox: {
				feature: {saveAsImage: {show: false,} }
			},
			xAxis: {
				type: 'category', boundaryGap: false, data: ['" . implode("','", $data['name']) . "'],axisLine: {show:true,lineStyle: {color: '#7f7f7f'}}
			},
			dataZoom:[
			    {
			        xAxisIndex:0,
			        show:false,
			        type:'slider',
			        startValue:0,
			        endValue:6,
			    }
			],
			yAxis: {
				type: 'value', axisLabel:{ margin: 30, },splitLine: {show: true,lineStyle: {type: 'dashed',color: '#383b59'}}".$yattr." //刻度标签与轴线之间的距离
			},
			series: [
				" . $series . "
			]
		};";
        return $this->echartsRool($option);
    }
    /**
     * echarts模板
     *
     * @param string $option
     * @param string $ext 扩展js
     * @return string
     */
    public function echartsRool($option, $ext = null): string
    {
        $id = suiji();
        return "
		<div id='" . $id . "' style='width:100%;height:100%;'></div>
        $ext
		<script type='text/javascript'>
		    function getZXT(){
                //基于准备好的dom，初始化echarts实例
                var myChart = echarts.init(document.getElementById('" . $id . "'),'walden');
                //指定图表的配置项和数据
                " . $option . "
                setInterval(function() {
                  if(option.dataZoom[0].endValue == dd.length){
                      option.dataZoom[0].endValue = 6;
                      option.dataZoom[0].startValue = 0;
                  }else{
                      option.dataZoom[0].endValue = option.dataZoom[0].endValue+1;
                      option.dataZoom[0].startValue = option.dataZoom[0].startValue+1;
                  }
                  //使用刚指定的配置项和数据显示图表。
			      myChart.setOption(option);
                },1000)
			}
			$(function() {
			  getZXT();
			})
			
		</script>
		";
    }
    /**
     * 产线进度数据
     */
    public function lineData(): bool|string
    {
        $page = $this->post('page')?:1;
        $sqlFirst = ($page - 1) * 5;
        $process_report = find(array(
            "table"=>"process_report",
            "field"=>"lineId,IFNULL(sum(yield),0) as num",
            "where"=>" coid = '".self::$coid."' and classify = '工序报工' and state = '已确认' group by lineId order by num desc limit {$sqlFirst},5 "
        ));
        if(empty($process_report['array'])){
            $process_report = find(array(
                "table"=>"process_report",
                "field"=>"lineId,IFNULL(sum(yield),0) as num",
                "where"=>" coid = '".self::$coid."' and classify = '工序报工' and state = '已确认' group by lineId order by num desc limit 0,5 "
            ));
        }
        $nextPage = count($process_report['array']) < 5?1:$page + 1;
        $li = "";
        foreach ((array)$process_report['array'] as $i=>$array){
            $product_line = query("product_line"," id = '$array[lineId]' ","name");
            $sendNum = find([
                    'table'  => "machining_send_order",
                    'field'  => "IFNULL(sum(num),0) as num",
                    'single' => " coid = '".self::$coid."' and classify = '生产派工' and state = '已确认' and lineId = '$array[lineId]' ",
                ])['num'] ?? 0;
            $rate = $sendNum>0?round($array['num']/$sendNum*100,1):0;
            $li .= "<li>
                    <span class='progress-name'>{$product_line['name']}</span>
                    <span class='progress-name'>{$rate}%</span>
                </li>";
        }
        // 拼接字符串
        $json['html'] = $li;
        $json['nextPage'] = $nextPage;
        return json_encode($json, 320);
    }
    /**
     * 饼图模板
     *
     * @param array $data 格式如上
     */
    public function pie($data)
    {
        $series = $legend = '';
        foreach ($data['series'] as $key => $array) {
            $legend .= "'{$array['name']}',";
            $value  = (is_array($array['data']) ? $array['data'][0] : $array['data']);
            $series .= '{value:"' . $value . '", name: "' . $array['name'] . '"},';
        }
        $color = "";
        if(isset($data['color'])){
            $color .= "color:[";
            foreach ($data['color'] as $v){
                $color .= "'{$v}',";
            }
            $color .= "],";
        }
        $option = <<<EOT
        var option = {
            legend: {
                data: [{$legend}]
            },
            tooltip: {
                trigger: 'item'
            },
            legend: {
                left: 'center',
                top: '5%',
            },
            title: {
                text: '{$data['text']}',
                subtext: '{$data['subtext']}',
                textStyle:{
                    color: '#fff'
                },
                subtextStyle:{
                    color: '#fff'
                },
                left: 'center',
                top: '55%'
            },
            {$color}
            series: [
                {
                    name: '',
                    type: 'pie',
                    radius: ['55%', '75%'],
                    center: ['50%', '60%'],
                    labelLine: {
                        length: '5%',
                    },
                    label: {
                        show: false,
                        // formatter: '{b}：{c}',
                    },
                    data: [{$series}]
                }
            ]
        };
EOT;
        //返回
        return $this->echartsPie($option);
    }
    /**
     * echarts模板
     *
     * @param string $option
     * @param string $ext 扩展js
     * @return string
     */
    public function echartsPie($option, $ext = null): string
    {
        $id = suiji();
        return "
		<div id='" . $id . "' style='width:100%;height:100%;'></div>
        $ext
		<script type='text/javascript'>
			//基于准备好的dom，初始化echarts实例
			var myChart = echarts.init(document.getElementById('" . $id . "'),'walden');
			//指定图表的配置项和数据
			" . $option . "
			//使用刚指定的配置项和数据显示图表。
			myChart.setOption(option);
			myChart.dispatchAction({
			    type:'highlight',
			    seriesIndex:0,
			    dataIndex:0,
			});
		</script>
		";
    }
    public function style(){
        return <<<EOT
        <style>
            body {
              margin:0px;
              background-color:rgba(242, 242, 242, 1);
              background-image:none;
              position:static;
              left:auto;
              width:1920px;
              margin-left:0;
              margin-right:0;
              text-align:left;
            }
            .form_sketch {
              border-color:transparent;
              background-color:transparent;
            }
            #base {
              position:absolute;
              z-index:0;
            }
            #u0_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:1920px;
              height:1080px;
              background:inherit;
              background-color:rgba(27, 31, 51, 1);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
            }
            #u0 {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:1920px;
              height:1080px;
              display:flex;
            }
            #u0 .text {
              position:absolute;
              align-self:center;
              padding:2px 2px 2px 2px;
              box-sizing:border-box;
              width:100%;
            }
            #u0_text {
              border-width:0px;
              word-wrap:break-word;
              text-transform:none;
              visibility:hidden;
            }
            #u1_img {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:1920px;
              height:1080px;
            }
            #u1 {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:1920px;
              height:1080px;
              display:flex;
              opacity:0.2;
            }
            #u1 .text {
              position:absolute;
              align-self:center;
              padding:2px 2px 2px 2px;
              box-sizing:border-box;
              width:100%;
            }
            #u1_text {
              border-width:0px;
              word-wrap:break-word;
              text-transform:none;
              visibility:hidden;
            }
            #u2_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:1872px;
              height:80px;
              background:inherit;
              background-color:rgba(44, 48, 64, 1);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
            }
            #u2 {
              border-width:0px;
              position:absolute;
              left:24px;
              top:17px;
              width:1872px;
              height:80px;
              display:flex;
              opacity:0.9;
            }
            #u2 .text {
              position:absolute;
              align-self:center;
              padding:2px 2px 2px 2px;
              box-sizing:border-box;
              width:100%;
            }
            #u2_text {
              border-width:0px;
              word-wrap:break-word;
              text-transform:none;
              visibility:hidden;
            }
            #u3_img {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:136px;
              height:38px;
            }
            #u3 {
              border-width:0px;
              position:absolute;
              left:42px;
              top:38px;
              width:136px;
              height:38px;
              display:flex;
            }
            #u3 .text {
              position:absolute;
              align-self:center;
              padding:2px 2px 2px 2px;
              box-sizing:border-box;
              width:100%;
            }
            #u3_text {
              border-width:0px;
              word-wrap:break-word;
              text-transform:none;
              visibility:hidden;
            }
            #ufull_img {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:30px;
              height:38px;
            }
            #ufull {
              border-width:0px;
              position:absolute;
              left:350px;
              top:38px;
              width:136px;
              height:38px;
              display:flex;
            }
            #ufull_text {
              border-width:0px;
              word-wrap:break-word;
              text-transform:none;
              visibility:hidden;
            }
            #u4_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:128px;
              height:37px;
              background:inherit;
              background-color:rgba(255, 255, 255, 0);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
              font-family:'Arial Normal', 'Arial';
              font-weight:400;
              font-style:normal;
              color:#F2F2F2;
            }
            #u4 {
              border-width:0px;
              position:absolute;
              left:166px;
              top:34px;
              width:128px;
              height:37px;
              display:flex;
              font-family:'Arial Normal', 'Arial';
              font-weight:400;
              font-style:normal;
              color:#F2F2F2;
            }
            #u4 .text {
              position:absolute;
              align-self:flex-start;
              padding:0px 0px 0px 0px;
              box-sizing:border-box;
              width:100%;
            }
            #u4_text {
              border-width:0px;
              white-space:nowrap;
              text-transform:none;
            }
            #u5 {
              position:absolute;
              left:1567px;
              top:49px;
            }
            #u5_state0 {
              position:relative;
              left:0px;
              top:0px;
              width:109px;
              height:17px;
              background-image:none;
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
            }
            #u5_state0_content {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:1px;
              height:1px;
            }
            #u6_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:103px;
              height:16px;
              background:inherit;
              background-color:rgba(255, 255, 255, 0);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:14px;
              letter-spacing:1px;
              color:#F2F2F2;
            }
            #u6 {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:103px;
              height:16px;
              display:flex;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:14px;
              letter-spacing:1px;
              color:#F2F2F2;
            }
            #u6 .text {
              position:absolute;
              align-self:flex-start;
              padding:0px 0px 0px 0px;
              box-sizing:border-box;
              width:100%;
            }
            #u6_text {
              border-width:0px;
              white-space:nowrap;
              text-transform:none;
            }
            #u5_state1 {
              position:relative;
              left:0px;
              top:0px;
              width:109px;
              height:17px;
              background-image:none;
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
              visibility:hidden;
            }
            #u5_state1_content {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:1px;
              height:1px;
            }
            #u7_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:103px;
              height:16px;
              background:inherit;
              background-color:rgba(255, 255, 255, 0);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:14px;
              letter-spacing:1px;
              color:#F2F2F2;
            }
            #u7 {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:103px;
              height:16px;
              display:flex;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:14px;
              letter-spacing:1px;
              color:#F2F2F2;
            }
            #u7 .text {
              position:absolute;
              align-self:flex-start;
              padding:0px 0px 0px 0px;
              box-sizing:border-box;
              width:100%;
            }
            #u7_text {
              border-width:0px;
              white-space:nowrap;
              text-transform:none;
            }
            #u8_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:495px;
              height:550px;
              background:inherit;
              background-color:rgba(44, 48, 64, 1);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
            }
            #u8 {
              border-width:0px;
              position:absolute;
              left:240px;
              top:107px;
              width:495px;
              height:550px;
              display:flex;
              opacity:0.9;
            }
            #u8 .text {
              position:absolute;
              align-self:center;
              padding:2px 2px 2px 2px;
              box-sizing:border-box;
              width:100%;
            }
            #u8_text {
              border-width:0px;
              word-wrap:break-word;
              text-transform:none;
              visibility:hidden;
            }
            #u9_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:495px;
              height:400px;
              background:inherit;
              background-color:rgba(44, 48, 64, 1);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
            }
            #u9 {
              border-width:0px;
              position:absolute;
              left:240px;
              top:667px;
              width:495px;
              height:400px;
              display:flex;
              opacity:0.9;
            }
            #u9 .text {
              position:absolute;
              align-self:center;
              padding:2px 2px 2px 2px;
              box-sizing:border-box;
              width:100%;
            }
            #u9_text {
              border-width:0px;
              word-wrap:break-word;
              text-transform:none;
              visibility:hidden;
            }
            #u10_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:206px;
              height:616px;
              background:inherit;
              background-color:rgba(44, 48, 64, 1);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
            }
            #u10 {
              border-width:0px;
              position:absolute;
              left:24px;
              top:107px;
              width:206px;
              height:616px;
              display:flex;
              opacity:0.9;
            }
            #u10 .text {
              position:absolute;
              align-self:center;
              padding:2px 2px 2px 2px;
              box-sizing:border-box;
              width:100%;
            }
            #u10_text {
              border-width:0px;
              word-wrap:break-word;
              text-transform:none;
              visibility:hidden;
            }
            #u11_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:700px;
              height:550px;
              background:inherit;
              background-color:rgba(44, 48, 64, 1);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
            }
            #u11 {
              border-width:0px;
              position:absolute;
              left:745px;
              top:107px;
              width:700px;
              height:550px;
              display:flex;
              opacity:0.9;
            }
            #u11 .text {
              position:absolute;
              align-self:center;
              padding:2px 2px 2px 2px;
              box-sizing:border-box;
              width:100%;
            }
            #u11_text {
              border-width:0px;
              word-wrap:break-word;
              text-transform:none;
              visibility:hidden;
            }
            #u12_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:441px;
              height:550px;
              background:inherit;
              background-color:rgba(44, 48, 64, 1);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
            }
            #u12 {
              border-width:0px;
              position:absolute;
              left:1455px;
              top:107px;
              width:441px;
              height:550px;
              display:flex;
              opacity:0.9;
            }
            #u12 .text {
              position:absolute;
              align-self:center;
              padding:2px 2px 2px 2px;
              box-sizing:border-box;
              width:100%;
            }
            #u12_text {
              border-width:0px;
              word-wrap:break-word;
              text-transform:none;
              visibility:hidden;
            }
            #u13_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:1151px;
              height:400px;
              background:inherit;
              background-color:rgba(44, 48, 64, 1);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
            }
            #u13 {
              border-width:0px;
              position:absolute;
              left:745px;
              top:667px;
              width:1151px;
              height:400px;
              display:flex;
              opacity:0.9;
            }
            #u13 .text {
              position:absolute;
              align-self:center;
              padding:2px 2px 2px 2px;
              box-sizing:border-box;
              width:100%;
            }
            #u13_text {
              border-width:0px;
              word-wrap:break-word;
              text-transform:none;
              visibility:hidden;
            }
            #u14_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:56px;
              height:16px;
              background:inherit;
              background-color:rgba(255, 255, 255, 0);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:14px;
              color:#F2F2F2;
            }
            #u14 {
              border-width:0px;
              position:absolute;
              left:692px;
              top:49px;
              width:56px;
              height:16px;
              display:flex;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:14px;
              color:#F2F2F2;
            }
            #u14 .text {
              position:absolute;
              align-self:flex-start;
              padding:0px 0px 0px 0px;
              box-sizing:border-box;
              width:100%;
            }
            #u14_text {
              border-width:0px;
              white-space:nowrap;
              text-transform:none;
            }
            #u15_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:76px;
              height:33px;
              background:inherit;
              background-color:rgba(255, 255, 255, 0);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:28px;
              color:#F2F2F2;
            }
            #u15 {
              border-width:0px;
              position:absolute;
              left:757px;
              top:41px;
              width:76px;
              height:33px;
              display:flex;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:28px;
              color:#F2F2F2;
            }
            #u15 .text {
              position:absolute;
              align-self:flex-start;
              padding:0px 0px 0px 0px;
              box-sizing:border-box;
              width:100%;
            }
            #u15_text {
              border-width:0px;
              white-space:nowrap;
              text-transform:none;
            }
            #u16_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:56px;
              height:16px;
              background:inherit;
              background-color:rgba(255, 255, 255, 0);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:14px;
              color:#F2F2F2;
            }
            #u16 {
              border-width:0px;
              position:absolute;
              left:900px;
              top:49px;
              width:56px;
              height:16px;
              display:flex;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:14px;
              color:#F2F2F2;
            }
            #u16 .text {
              position:absolute;
              align-self:flex-start;
              padding:0px 0px 0px 0px;
              box-sizing:border-box;
              width:100%;
            }
            #u16_text {
              border-width:0px;
              white-space:nowrap;
              text-transform:none;
            }
            #u17_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:76px;
              height:33px;
              background:inherit;
              background-color:rgba(255, 255, 255, 0);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:28px;
              color:#F2F2F2;
            }
            #u17 {
              border-width:0px;
              position:absolute;
              left:966px;
              top:41px;
              width:76px;
              height:33px;
              display:flex;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:28px;
              color:#F2F2F2;
            }
            #u17 .text {
              position:absolute;
              align-self:flex-start;
              padding:0px 0px 0px 0px;
              box-sizing:border-box;
              width:100%;
            }
            #u17_text {
              border-width:0px;
              white-space:nowrap;
              text-transform:none;
            }
            #u18_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:42px;
              height:16px;
              background:inherit;
              background-color:rgba(255, 255, 255, 0);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:14px;
              color:#F2F2F2;
            }
            #u18 {
              border-width:0px;
              position:absolute;
              left:1109px;
              top:49px;
              width:42px;
              height:16px;
              display:flex;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:14px;
              color:#F2F2F2;
            }
            #u18 .text {
              position:absolute;
              align-self:flex-start;
              padding:0px 0px 0px 0px;
              box-sizing:border-box;
              width:100%;
            }
            #u18_text {
              border-width:0px;
              white-space:nowrap;
              text-transform:none;
            }
            #u19_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:63px;
              height:33px;
              background:inherit;
              background-color:rgba(255, 255, 255, 0);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              color:#F2F2F2;
            }
            #u19 {
              border-width:0px;
              position:absolute;
              left:1161px;
              top:41px;
              width:63px;
              height:33px;
              display:flex;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              color:#F2F2F2;
            }
            #u19 .text {
              position:absolute;
              align-self:flex-start;
              padding:0px 0px 0px 0px;
              box-sizing:border-box;
              width:100%;
            }
            #u19_text {
              border-width:0px;
              white-space:nowrap;
              text-transform:none;
            }
            #u20_img {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:2px;
              height:13px;
            }
            #u20 {
              border-width:0px;
              position:absolute;
              left:865px;
              top:52px;
              width:1px;
              height:12px;
              display:flex;
            }
            #u20 .text {
              position:absolute;
              align-self:center;
              padding:2px 2px 2px 2px;
              box-sizing:border-box;
              width:100%;
            }
            #u20_text {
              border-width:0px;
              word-wrap:break-word;
              text-transform:none;
              visibility:hidden;
            }
            #u21_img {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:2px;
              height:13px;
            }
            #u21 {
              border-width:0px;
              position:absolute;
              left:1074px;
              top:52px;
              width:1px;
              height:12px;
              display:flex;
            }
            #u21 .text {
              position:absolute;
              align-self:center;
              padding:2px 2px 2px 2px;
              box-sizing:border-box;
              width:100%;
            }
            #u21_text {
              border-width:0px;
              word-wrap:break-word;
              text-transform:none;
              visibility:hidden;
            }
            #u22_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:64px;
              height:19px;
              background:inherit;
              background-color:rgba(255, 255, 255, 0);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:16px;
              color:#F2F2F2;
            }
            #u22 {
              border-width:0px;
              position:absolute;
              left:42px;
              top:127px;
              width:64px;
              height:19px;
              display:flex;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:16px;
              color:#F2F2F2;
            }
            #u22 .text {
              position:absolute;
              align-self:flex-start;
              padding:0px 0px 0px 0px;
              box-sizing:border-box;
              width:100%;
            }
            #u22_text {
              border-width:0px;
              white-space:nowrap;
              text-transform:none;
            }
            #review_box {
              border-width:0px;
              position:absolute;
              left:42px;
              top:166px;
              width:170px;
              height:538px;
              overflow: hidden;
              color: #fff;
            }
            #u23_state0 {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:170px;
              height:538px;
              -ms-overflow-x:hidden;
              overflow-x:hidden;
              -ms-overflow-y:hidden;
              overflow-y:hidden;
              background-image:none;
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
            }
            #u23_state0_content {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:1px;
              height:1px;
            }
            #u36_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:206px;
              height:344px;
              background:inherit;
              background-color:rgba(44, 48, 64, 1);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
            }
            #u36 {
              border-width:0px;
              position:absolute;
              left:24px;
              top:723px;
              width:206px;
              height:344px;
              display:flex;
              opacity:0.9;
            }
            #u36 .text {
              position:absolute;
              align-self:center;
              padding:2px 2px 2px 2px;
              box-sizing:border-box;
              width:100%;
            }
            #u36_text {
              border-width:0px;
              word-wrap:break-word;
              text-transform:none;
              visibility:hidden;
            }
            #u37_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:96px;
              height:19px;
              background:inherit;
              background-color:rgba(255, 255, 255, 0);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:16px;
              color:#F2F2F2;
            }
            #u37 {
              border-width:0px;
              position:absolute;
              left:42px;
              top:723px;
              width:96px;
              height:19px;
              display:flex;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:16px;
              color:#F2F2F2;
            }
            #u37 .text {
              position:absolute;
              align-self:flex-start;
              padding:0px 0px 0px 0px;
              box-sizing:border-box;
              width:100%;
            }
            #u37_text {
              border-width:0px;
              white-space:nowrap;
              text-transform:none;
            }
            #line_progress {
              border-width:0px;
              position:absolute;
              left:42px;
              top:761px;
              width:170px;
              height:293px;
            }
            #u38_state0 {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:170px;
              height:293px;
              -ms-overflow-x:hidden;
              overflow-x:hidden;
              -ms-overflow-y:hidden;
              overflow-y:hidden;
              background-image:none;
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
            }
            #u38_state0_content {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:1px;
              height:1px;
            }
            #u79 {
              border-width:0px;
              position:absolute;
              left:260px;
              top:127px;
              width:96px;
              height:19px;
              display:flex;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:16px;
              color:#F2F2F2;
            }
            #u79 .text {
              position:absolute;
              align-self:flex-start;
              padding:0px 0px 0px 0px;
              box-sizing:border-box;
              width:100%;
            }
            #u79_text {
              border-width:0px;
              white-space:nowrap;
              text-transform:none;
            }
            #u80_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:64px;
              height:19px;
              background:inherit;
              background-color:rgba(255, 255, 255, 0);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:16px;
              color:#F2F2F2;
            }
            #u80 {
              border-width:0px;
              position:absolute;
              left:765px;
              top:127px;
              width:64px;
              height:19px;
              display:flex;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:16px;
              color:#F2F2F2;
            }
            #u80 .text {
              position:absolute;
              align-self:flex-start;
              padding:0px 0px 0px 0px;
              box-sizing:border-box;
              width:100%;
            }
            #u80_text {
              border-width:0px;
              white-space:nowrap;
              text-transform:none;
            }
            #u81_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:64px;
              height:19px;
              background:inherit;
              background-color:rgba(255, 255, 255, 0);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:16px;
              color:#F2F2F2;
            }
            #u81 {
              border-width:0px;
              position:absolute;
              left:1475px;
              top:127px;
              width:64px;
              height:19px;
              display:flex;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:16px;
              color:#F2F2F2;
            }
            #u81 .text {
              position:absolute;
              align-self:flex-start;
              padding:0px 0px 0px 0px;
              box-sizing:border-box;
              width:100%;
            }
            #u81_text {
              border-width:0px;
              white-space:nowrap;
              text-transform:none;
            }
            #u82_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:64px;
              height:19px;
              background:inherit;
              background-color:rgba(255, 255, 255, 0);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:16px;
              color:#F2F2F2;
            }
            #u82 {
              border-width:0px;
              position:absolute;
              left:260px;
              top:687px;
              width:64px;
              height:19px;
              display:flex;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:16px;
              color:#F2F2F2;
            }
            #u82 .text {
              position:absolute;
              align-self:flex-start;
              padding:0px 0px 0px 0px;
              box-sizing:border-box;
              width:100%;
            }
            #u82_text {
              border-width:0px;
              white-space:nowrap;
              text-transform:none;
            }
            #u83_div {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:137px;
              height:19px;
              background:inherit;
              background-color:rgba(255, 255, 255, 0);
              border:none;
              border-radius:0px;
              -moz-box-shadow:none;
              -webkit-box-shadow:none;
              box-shadow:none;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              color:#F2F2F2;
            }
            #u83 {
              border-width:0px;
              position:absolute;
              left:765px;
              top:687px;
              width:137px;
              height:19px;
              display:flex;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              color:#F2F2F2;
            }
            #u83 .text {
              position:absolute;
              align-self:flex-start;
              padding:0px 0px 0px 0px;
              box-sizing:border-box;
              width:100%;
            }
            #u83_text {
              border-width:0px;
              white-space:nowrap;
              text-transform:none;
            }
            #yieldWaveHtml {
              border-width:0px;
              position:absolute;
              left:762px;
              top:716px;
              width:1100px;
              height:304px;
            }
           
 
            #u451 {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:0px;
              height:0px;
            }
            
            #u453 {
                border-width: 0px;
                position: absolute;
                left: 1225px;
                top: 166px;
                width: 190px;
                height: 190px;
            }
            #u480 {
              border-width:0px;
              position:absolute;
              left:1225px;
              top:127px;
              width:135px;
              height:19px;
              display:flex;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:16px;
              color:#F2F2F2;
            }
            #u480 .text {
              position:absolute;
              align-self:flex-start;
              padding:0px 0px 0px 0px;
              box-sizing:border-box;
              width:100%;
            }
            #u480_text {
              border-width:0px;
              white-space:nowrap;
              text-transform:none;
            }
            #u481 {
              border-width:0px;
              position:absolute;
              left:0px;
              top:0px;
              width:0px;
              height:0px;
            }
            #u483 {
                border-width: 0px;
                position: absolute;
                left: 1225px;
                top: 454px;
                width: 190px;
                height: 190px;
            }
            #u510 {
              border-width:0px;
              position:absolute;
              left:1225px;
              top:415px;
              width:103px;
              height:19px;
              display:flex;
              font-family:'Lato';
              font-weight:400;
              font-style:normal;
              font-size:16px;
              color:#F2F2F2;
            }
            #u510 .text {
              position:absolute;
              align-self:flex-start;
              padding:0px 0px 0px 0px;
              box-sizing:border-box;
              width:100%;
            }
            #u510_text {
              border-width:0px;
              white-space:nowrap;
              text-transform:none;
            }
            #u511 {
              border-width:0px;
              position:absolute;
              left:765px;
              top:166px;
              width:429px;
              height:478px;
            }
            #u4 p{
                font-size: 32px!important;
                line-height: 37px!important;
            }
            ._三级标题 p{
                font-size: 16px!important;
            }
            .quantity{
                text-decoration: none;
                font-size: 28px!important;
                line-height: 38px;
                margin-left: 5px;
            }
            progress {
                width: 166px;
                height: 10px;
                background-color: rgb(81 84 96);
                border-radius: 1em;
                /*bgc 需要被设置，否则背景色无法被显示出来*/
            }
    
            /* 表示总长度背景色 */
            progress::-webkit-progress-bar {
                border-radius: 1em;
                background-color: rgb(81 84 96);
            }
            /* 表示已完成进度背景色 */
            progress::-webkit-progress-value {
                border-radius: 1em;
                background: rgb(83 129 221);
            }
            .progress-name{
                width: 48%;
                display: inline-block;
                text-align: center;
                height: 50px;
                line-height: 50px;
                background-color: #373b51;
                font-size: 16px;
                color: #fff;
                margin: 3px 0;
                overflow: hidden;
                vertical-align: middle;
                white-space: nowrap;
                text-overflow: ellipsis;
            }
            #u201 {
              position:absolute;
              left:260px;
              top:727px;
            }
            .make-title{
                display: flex;
                justify-content: space-around;
                background-color: #464a66;
                color: #fff;
            }
            /********制造费用******/
            #make_cost_box{
                height: 300px!important;
                overflow: hidden;
                font-size: 14px;
                color: #fff;
            }
            .make-title span{
                 width: 20%;
                 text-align: center;
            }
            #make_cost_box li{
                display: flex;
                justify-content: space-around;
                height: 35px;
                line-height: 35px;
            }
            #make_cost_box li:nth-child(2n-1){
                background-color: #383d52;
            }
            #make_cost_box li:nth-child(1){
                margin: 0 0 10px 0!important;
            }
            #make_cost_box span{
                width: 20%;
                text-align: center;
            }
            li span:nth-child(3),li span:nth-child(4),li span:nth-child(5){
                color: rgb(80, 122, 209);
            }
            /*****材料耗用*****/
            #material_box progress {
                width: 160px;
                height: 10px;
                background-color: rgb(81 84 96);
                border-radius: 1em;
                margin-left: 10px;
            }
            #material_box li {
                display: flex;
                justify-content: space-between;
                align-items: center;
                white-space: nowrap;
                overflow: hidden;
                margin: 15px 0;
            }
            .difference{
                color: #f58989;
                text-align: center;
                display: inline-block;
                width: 55px;
            }
            #material_box{
                height: 468px!important;
                overflow: hidden;
                color: #fff;
            }
            #time_piece_box{
                height: 456px!important;
                overflow: hidden;
                font-size: 14px;
                color: #fff;
            }
            .piece-title,.make-title{
                display: flex;
                justify-content: space-around;
                background-color: #383d52;
                color: #fff;
            }
            .piece-title span{
                 width: 25%;
                 text-align: center;
            }
            #time_piece_box li{
                display: flex;
                justify-content: space-around;
                height: 35px;
                line-height: 35px;
            }
            #time_piece_box li:nth-child(2n-1){
                background-color: #383d52;
            }
            #time_piece_box li:nth-child(1){
                /*margin: 0 0 10px 0!important;*/
            }
            #time_piece_box span{
                width: 25%;
                text-align: center;
            }
            .material-name{
                width: 220px;
                height: 28px;
                line-height: 28px;
            }
            .consumption-situation{
                width: 200px;
            }
            .progress-text{
                width: 50px;
                display: inline-block;
                overflow: hidden;
                vertical-align: middle;
                white-space: nowrap;
                text-overflow: ellipsis;
                font-size: 12px;
            }
            .m-name{
                width: 150px;
                text-align: left;
                display: inline-block;
                overflow: hidden;
                vertical-align: middle;
                white-space: nowrap;
                text-overflow: ellipsis;
            }
            #u318 {
              position:absolute;
              left:1475px;
              top:167px;
            }
            #delayHtml {
              border-width:0px;
              position:absolute;
              left:260px;
              top:166px;
              width:454px;
              height:200px;
              display:flex;
            }
            #onScheduleHtml {
              border-width:0px;
              position:absolute;
              left:260px;
              top:372px;
              width:454px;
              height:260px;
              display:flex;
            }
            #categoryActualHtml {
                width: 190px;
                height: 190px;
                position: relative;
            }
            #categoryExceedHtml {
                width: 190px;
                height: 190px;
                position: relative;
            }
            #pieTextActual,#pieTextExceed{
                transition: 0.8s;
                color: #fff;
                position: absolute;
                top: 100px;
                left: 52px;
            }
            .actual-name,.exceed-name{
                font-size: 16px;
                text-align: center;
                width: 87px;
                overflow: hidden;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
                -o-text-overflow: ellipsis;
            }
            .actual-rate,.exceed-rate{
                text-align: center;
                width: 87px;
            }
    </style>
EOT;
    }

    /**
     * 计算 计件系数和计件工时和
     */
    public function caculate($teamId,$date): float|int
    {
        $total = 0;
        $team_detail = find(array(
            'table'=>'team_detail',
            'where'=>"orderId = '$teamId'"
        ));
        foreach ($team_detail['array'] as $array){
            $workshop_clock_detail = find(array(
                'table'=>'workshop_clock as a join workshop_clock_detail as b on a.id = b.orderId',
                'single'=>"a.state !='草稿' and a.teamId like '%$teamId%' and b.stid = '$array[stid]' and b.recordDate = '$date'",
                'field'=>"b.hour"
            ));
            $workshop_clock_detail['hour'] = $workshop_clock_detail['hour']??0;
            $total+=$array['rate']*$workshop_clock_detail['hour'];
        }
        return $total;
    }
}
